package com.yxy.controller;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.sun.glass.ui.Size;
import com.yxy.pojo.Pet;
import com.yxy.pojo.PetInfo;
import com.yxy.service.PetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Controller
public class PetController {
    @Autowired
    private PetService ps;
    @RequestMapping("/page")
    @ResponseBody
    public PetInfo getpage(Integer page,Integer rows){
        PageInfo<Pet>ppp=ps.pageAll(page,rows);
        PetInfo p=new PetInfo();
        p.setRows(ppp.getList());
        p.setTotal(ppp.getTotal());
        return p;
    }
    @RequestMapping("/usersave")
    @ResponseBody
    public String add(Pet p){

        int a=ps.add(p);
        System.out.println("save"+p.getPetname()+p.getPetbreed()+p.getPetsex()+":"+p.getBirthday());
        return "ok";
    }

    @RequestMapping("/edituser")
    @ResponseBody
    public String update(Pet p, Integer petid){
        p.setPetid(petid);
        int a=ps.update(p);
        return "ok";
    }

    @RequestMapping("/delusers")
    @ResponseBody
    public String delete(Integer id){
        int a=ps.delete(id);
        System.out.println(a);
        return "ok";
    }

}

